class Solution
{
public:
    int minimumRecolors(string blocks, int k)
    {
        int wCount = 0;
        for (int i = 0; i < k; ++i)
        {
            if (blocks[i] == 'W')
            {
                ++wCount;
            }
        }
        int minWCount = wCount;
        int n = blocks.size();
        for (int i = 1; i <= n - k; ++i)
        {
            if (blocks[i - 1] == 'W')
            {
                --wCount;
            }
            if (blocks[i + k - 1] == 'W')
            {
                ++wCount;
            }
            minWCount = min(minWCount, wCount);
        }
        return minWCount;
    }
};